package client;

import java.awt.Graphics;

/**
 * Responsible for formatting complex graphics issues.
 * @author Robz
 *
 */
public class GraphicsFormatter {

	public GraphicsFormatter() {

	}

	/**
	 * 
	 * @param x X-Coord
	 * @param y Y-Coord
	 * @param charLimit How many characters per line
	 * @param text The String to draw
	 * @param g Graphics object
	 */
	public void drawLongString(int x, int y, int charLimit, String text, Graphics g) {
        char[] chars = text.toCharArray();
        boolean endOfString = false;
        int start = 0;
        int end = start;
        while(start < chars.length-1) {
            int charCount = 0;
            int lastSpace = 0;
            while(charCount < charLimit) {
                if(chars[charCount+start] == ' ') {
                    lastSpace = charCount;
                }
                charCount++;
                if(charCount+start == text.length()) {
                    endOfString = true;
                    break;
                }
            } 
            end = endOfString ? text.length()
                              : (lastSpace > 0) ? lastSpace+start : charCount+start;
            g.drawString((text.substring(start, end)), x, y);
            start = end+1;
            y+=20;
            
            
        }
	}

}
